Home:ALL Converter>How to create a complex Javascript object

How to create a complex Javascript object

Ask Time:2020-02-24T01:11:24         Author:James Quek

Json Formatter

I am new to JavaScript and Python, and programming in general.

I want to store data about common English phonograms in a JavaScript data object. There are about 80 phonograms. Each phonogram has one or more possible pronunciations. Each phonogram’s pronunciation would have a list of one or more word examples (say, 30 maximum) which would include the IPA phonetic symbols and a translation to a foreign language. E.g., the phonogram ‘ea’ has three pronunciation,

(1) 'iːˈ, (2)ˈɛˈ & (3)ˈeɪˈ:

(1)ˈbeadˈ, 'feat', 'beat'... (2)'bread', 'head', 'dead'... (3)'break'...

Is there a built-in data structure best suited for this? I am thinking of a class to make these objects and store it in an array or something. And how should I write my text for populating the the data objects?

Author:James Quek,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60364723/how-to-create-a-complex-javascript-object
T.J. Crowder :

JavaScript has four fundamental structured data types:\n\n\nobjects, which have properties, which have keys (names which are strings or Symbols) and values (any type)\narrays, which have elements, which have indexes and values (arrays are technically objects, but ignore that for now)\nMap, which has entries, which have keys (any type) and values (any type)\nSet, which has unique entries of any type (probably not useful for what you're doing)\n\n\nIt sounds like you'd probably want either an object or a Map where the keys are the phonographs and the values are objects. Within each object, you'd probably have another Map or object keyed by the pronunciation where the values are objects giving further information (examples and translations).\n\nHere's an example using Maps, which you initialize by passing an array of arrays into the Map constructor:\n\nconst data = new Map([\n [\n \"ea\", \n {\n pronunciations: new Map([\n [\n \"iː\",\n {\n examples: [\"bead\", \"feat\"],\n transations: [/*...*/]\n }\n ]\n ]),\n otherInfo: /*...*/\n }\n ],\n // ...the other 79 entries...\n]);\n\n\nGetting the data for an entry based on the phonogram:\n\nconst entry = data.get(\"ea\");\n\n\nThe entry object will have a pronunciations property with a Map of the pronunciations and the objects (with examples and translations) they map to.\n\nMore on MDN:\n\n\nMap\nObject\nArray\n",
2020-02-23T17:23:22
yy